package com.war.dao.outOfStorage;

import com.war.pojo.outofstorage.ProductOut;
import com.war.pojo.outofstorage.ProductReturn;
import com.war.pojo.system.Customer;
import com.war.pojo.system.Product;
import com.war.pojo.system.Warehouse;
import com.war.pojo.warehousing.PurchaseInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductReturnDao {
    //查询
    @Select("select * from outofstorage_return,outofstorage_out where outofstorage_out.outId=outofstorage_return.outId and outofstorage_return.status=1")
    List<ProductReturn> select(ProductReturn pr);

    //根据id查询
    @Select("select * from outofstorage_return,outofstorage_out where returnId=#{returnId} and outofstorage_out.outId=outofstorage_return.outId")
    ProductReturn selectByReturnId(ProductReturn pr);

    //删除信息
    @Update("update outofstorage_return set status=0 where returnId=#{returnId}")
    int delInfo(ProductReturn pr);

    //根据产品名称查询
    @Select("select * from  outofstorage_return,outofstorage_out where productName=#{conValue} and outofstorage_return.status=1 and outofstorage_out.outId=outofstorage_return.outId")
    List<ProductReturn> selectByProductName(ProductReturn pr);
    //根据客户查询
    @Select("select * from  outofstorage_return,outofstorage_out where clientName=#{conValue} and outofstorage_return.status=1 and outofstorage_out.outId=outofstorage_return.outId")
    List<ProductReturn> selectByClientName(ProductReturn pr);
    //根据出库日期范围查询
    @Select("select * from  outofstorage_return,outofstorage_out where returnDate between #{startDate} and #{endDate} and outofstorage_out.outId=outofstorage_return.outId and outofstorage_return.status=1\n"+
            "order by str_to_date(returnDate,'%Y-%m-%d')")
    List<ProductReturn> selectByDate(ProductReturn pr);
    //修改信息
    @Update("update outofstorage_return set productName=#{productName},returnDate=#{returnDate},returnQuantity=#{returnQuantity},clientName=#{clientName},returnReason=#{returnReason},returnAmount=#{returnAmount},administrator=#{administrator},warehouseName=#{warehouseName} where returnId=#{returnId}")
    int update(ProductReturn pr);

    //退货
    @Insert("insert into outofstorage_return (outId,productName,returnDate,returnQuantity,returnReason,returnAmount,clientName,administrator,warehouseName)" +
            " value(#{outId},#{productName},#{returnDate},#{returnQuantity},#{returnReason},#{returnAmount},#{clientName},#{administrator},#{warehouseName})")
    int addReturn(ProductReturn pr);

    //批量删除
    @Delete("delete from outofstorage_return where returnId=#{returnId}")
    int delAll(ProductReturn pr);

    //查询入库数量
    @Select("SELECT storageNum FROM outofstorage_out where outId=#{outId}")
    int storageNumNow(ProductReturn po);

    //查询客户姓名
    @Select("select distinct(legal_person) from sys_customer")
    List<Customer> selectClientName();


    //查询仓库名称
    @Select("select distinct(name) from sys_warehouse")
    List<Warehouse> selectWarehouseName();

    //查询仓库的管理员名称
    @Select("select manager from sys_warehouse where name=#{name}")
    String getAdministrator(Warehouse warehouse);

}
